package com.springmvc.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.springmvc.entity.User;

@Controller
@RequestMapping("/user")
public class UserController {

	/**
	 * 1. 通过参数接收信息
	 */
	@RequestMapping(value = "/login1", method = RequestMethod.POST)
	public String login1(String userName, String password) {
		System.out.println("userName is:" + userName);
		System.out.println("password is:" + password);
		return "/WEB-INF/jsp/hello.jsp";
	}

	/**
	 * 2. 通过request接收
	 */
	@RequestMapping("/login2")
	public String login2(HttpServletRequest request) {
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		System.out.println("userName is:" + userName);
		System.out.println("password is:" + password);
		return "/WEB-INF/jsp/hello.jsp";
	}

	/**
	 * 3. 通过bean接收
	 */
	@RequestMapping("/login3")
	public String login3(User user) {
		System.out.println("userName is:" + user.getUserName());
		System.out.println("password is:" + user.getPassword());
		return "/WEB-INF/jsp/hello.jsp";
	}
}
